<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8" isELIgnored="false"%>

<%
	request.setAttribute("title", "员工详情");
	request.setAttribute("modelConfigPath", "personnel");
%>

<%@ include file="/WEB-INF/views/shared/master/contentHeader.jsp"%>
<style type="text/css">
.content{
margin-bottom:28px;
}
</style>

<t:panel cssClass="panel-flat form-detailed form-xs" customBody="true"
	customHead="true">
	<div class="detailed-navbar-content panel-body content">
		<t:form commandName="personnel" action="/admin/personnel/personnel/save"
			method="post" cssClass="form-horizontal">
			<div class="hide">
				<t:hidden path="employeeId"/>
				<input type="hidden" id="initRoleIds" value="${roleIds}" /> 
			</div>
			<t:formgroup>
				<div class="col-sm-6">
					<t:label path="employeeName" cssClass="col-sm-4" />
					<t:input path="employeeName" colClass="col-sm-8" />
				</div>
				<div class="col-sm-6">
					<t:label path="employeeCode" cssClass="col-sm-4" />
					<t:input path="employeeCode" colClass="col-sm-8" cssClass="markCode" data-markCodeFor="employeeName"/>
				</div>
			</t:formgroup>
			<t:formgroup>
				<div class="col-sm-6">
					<t:label path="employeeAccount"  cssClass="col-sm-4"  />
					<t:input path="employeeAccount" data-markCodeFor="employeeName" data-markFilter="account" colClass="col-sm-8" cssClass="markCode" />
				</div>
				<div class="col-sm-6">
					<t:label path="mobile" cssClass="col-sm-4" />
					<t:input path="mobile" colClass="col-sm-8" />
				</div>
			</t:formgroup>
			<t:formgroup>
				<div class="col-sm-6">
					<t:label path="birthday" cssClass="col-sm-4" />
					<t:date path="birthday" colClass="col-sm-8"/>
				</div>
				<div class="col-sm-6">
					<t:label path="sex" cssClass="col-sm-4" />
					<t:selectButton path="sex" colClass="col-sm-8" />
				</div>
			</t:formgroup>
			<t:formgroup>
				<div class="col-sm-6">
					<t:label path="email" cssClass="col-sm-4" />
					<t:input path="email" colClass="col-sm-8"/>
				</div>
				<div class="col-sm-6">
					<t:label path="qq" cssClass="col-sm-4" />
					<t:input path="qq" colClass="col-sm-8"/>
				</div>
			</t:formgroup>
			<t:formgroup>
				<div class="col-sm-6">
					<t:label path="jobDuty" cssClass="col-sm-4" />
					<t:select2 path="jobDuty" readonly="true" colClass="col-sm-8"/>
				</div>
				<div class="col-sm-6">
					<t:label path="joinUsDate" cssClass="col-sm-4" />
					<t:date path="joinUsDate" colClass="col-sm-8"/>
				</div>
			</t:formgroup>
			<t:formgroup>
				<div class="col-sm-6">
					<t:label path="idCard" cssClass="col-sm-4" />
					<t:input path="idCard" colClass="col-sm-8"/>
				</div>
				<div class="col-sm-6">
					<t:label path="liveAddress" cssClass="col-sm-4" />
					<t:select2 path="provinceId" colClass="col-sm-4"/>
					<t:select2 path="cityId" colClass="col-sm-4"/>
				</div>
			</t:formgroup>
			<t:formgroup>
				<div class="col-sm-12">
					<t:label path="businessId" cssClass="col-sm-2" />
					<t:select2  path="businessId" colClass="col-sm-10"/>
				</div>  
			</t:formgroup>
			<t:formgroup>
				<div class="col-sm-12">
					<t:label path="roleIds" cssClass="col-sm-2" />
					<t:select2 path="roleIds" multiple="true" colClass="col-sm-10" />
				</div>
			</t:formgroup>
			<t:formgroup>
				<div class="" style="width: 17%; float: left;">
					<t:label path="userMark" cssClass="col-sm-10" />
				</div>
				<div class="" style="width: 83%; float: left;">
					<t:input path="userMark" style="height:120px;"
						cssClass="col-sm-10" />
				</div>
			</t:formgroup>
		</t:form>
	</div>
	<div class="navbar-fixed-bottom">
	<t:panelFoot headingBtnCssClass="heading-btn pull-right-important">
		<t:button icon="icon-floppy-disk" onclick="saveData()"
			cssClass="btn-info" csize="sm">保存</t:button>
	</t:panelFoot>
	</div>
</t:panel>

<script type="text/javascript">

function saveData(){
	if (!$("form:first").valid()){
		return;
	}
	$("form:first").submit();
}

  $(function(){
	var buId=$("#businessId").val();
	var initRoleIds=$("#initRoleIds").val();
	c.log(initRoleIds);
	loadRoleSelect2(buId,initRoleIds)
	
}); 

 function loadRoleSelect2(buId,initRoleIds){
	$("#roleIds option").remove();
	if($.isNull(buId)){
		return;
	}
	var url=$.getVirtualPath()+"/admin/superbase/role/getRoleByBuId?buId="+buId;
	var roles=$.getJsonPost(url);
	if($.isNull(roles)){
		return;
	}
	var options=[];
	
	$.each(roles,function(index,role){
		var selected="";
		if(!$.isNull(initRoleIds)){
			selected=initRoleIds.indexOf(role.roleId)>=0?"selected=selected":"";	
		}
		
		options.push("<option "+selected+" value='"+role.roleId+"'>"+role.roleName+"</option>");
	});
	
	$("#roleIds").append(options);
 };  
 
 $(function(){
	 $("#provinceId").on("change",function(){
		 var provinceId=$("#provinceId").val();
		 loadProvinceSelect2(provinceId); 
	}); 
	initProvinceCity();
	
});

function initProvinceCity(){
	var provinceId=$("#provinceId").val();
	var cityId=$("#cityId").val();
	if($.isNull(provinceId)){
		 provinceId = 'all';
		 loadProvinceSelect2(provinceId); 
	}else{
		loadProvinceSelect2(provinceId,cityId);
	}
	
};

function loadProvinceSelect2(keyId,cityId){
	
	$("#provinceId option").remove();
	$("#cityId option").remove();
	
	var url=$.getVirtualPath()+"/admin/team/cooperationTeam/provinceCity?keyId=all";
	var provinces =$.getJsonPost(url);
    var optProvince=[];
    
    $.each(provinces,function(index,province){
		var proSelected="";
		proSelected=province.id.indexOf(keyId)>=0?"selected=selected":"";	
		optProvince.push("<option "+proSelected+" value='"+province.id+"'>"+province.paramValue+"</option>");
    });
    $("#provinceId").append(optProvince);
    
    
    url=$.getVirtualPath()+"/admin/team/cooperationTeam/provinceCity?keyId=" + $("#provinceId").val();
	var citys =$.getJsonPost(url);
    var optCity=[];
    
    $.each(citys,function(index,city){
		var citySelected="";
		citySelected=city.id.indexOf(cityId)>=0?"selected=selected":"";	
		optCity.push("<option "+citySelected+" value='"+city.id+"'>"+city.paramValue+"</option>");
    });
    $("#cityId").append(optCity);
}
</script>
<th class="pager-th absolute-pos">
<%@ include file="/WEB-INF/views/shared/master/pager.jsp"%></th>
<%@ include file="/WEB-INF/views/shared/base/scripts/jqueryui.jsp"%>
<%@ include file="/WEB-INF/views/shared/base/scripts/limitless/default/formselects.jsp"%>
<%@ include file="/WEB-INF/views/shared/base/scripts/limitless/default/formstyling.jsp"%>
<%@ include file="/WEB-INF/views/shared/base/scripts/limitless/default/formselects.jsp"%>
<%@ include file="/WEB-INF/views/shared/master/dialog.jsp"%>
<%@ include file="/WEB-INF/views/shared/master/contentFooter.jsp"%>
